//
//  LZSArticelDetailViewController.m
//  IOSProject
//
//  Created by lzs on 2018/4/20.
//  Copyright © 2018年 com.linzhisheng. All rights reserved.
//

#import "LZSArticelDetailViewController.h"

@interface LZSArticelDetailViewController ()
@property (nonatomic, strong) UIWebView *webView;

@end

@implementation LZSArticelDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"文章详情";
    
    //添加webview
    self.webView = [[UIWebView alloc]initWithFrame:CGRectZero];
    self.webView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.webView];
    
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    
    if (self.srcStr.length==0) {
        self.srcStr = @"暂无";
    }
    
     NSString *htmls = [self getHtmlString];
    
    [self.webView loadHTMLString:htmls baseURL:nil];
}

#pragma mark - other
/// 拼接完整的html字符串：新添加了title， time的CSS样式
- (NSString *)getHtmlString
{
    NSMutableString *html = [NSMutableString string];
    [html appendString:@"<html>"];
    [html appendString:@"<head>"];
    [html appendFormat:@"<link rel=\"stylesheet\" href=\"%@\">",[[NSBundle mainBundle] URLForResource:@"xxx.css" withExtension:nil]];
    [html appendFormat:@"<style>img{max-width:%fpx !important;}</style>",self.view.frame.size.width-40];
    [html appendString:@"</head>"];
    [html appendString:@"<body style=\"background:#ffffff\">"];
    [html appendString:[self getBodyString]];
    [html appendString:@"</body>"];
    [html appendString:@"</html>"];
    
    return html;
}

/// 拼接body内容：包含了title， time， content
- (NSString *)getBodyString
{
    NSMutableString *body = [NSMutableString string];
    [body appendFormat:@"<div style =\"font-size:13px;font-weight:bold;color:#000 ;padding-top:15px;text-align:center \" class=\"title\">%@</div>",self.titlestr];
    [body appendFormat:@"<div style=\"font-size:12px;padding-top:8px;text-align:center;color:#a6a6a6 ;text-decoration:none\" class=\"time\">来源:%@           发布:%@</div>",self.srcStr,self.timestr];
    //    [body appendString:@"<hr style=\"border:0.5px solid #d8d8d8\">"];
    [body appendString:@"<div style=\"margin: 8px 8px 5px 8px;border-top:1px dotted #d8d8d8;\"></div>"];
    if (self.content != nil) {
        [body appendFormat:@"<div style =\"font-size:14px;\" class=\"title\">%@</div>",self.content];
    }
    return body;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
